package com.elitel.frame.business.service.impl;

import com.elitel.frame.base.component.CacheConfig;
import com.elitel.frame.business.service.SingleTableServerService;
import com.elitel.frame.main.entity.CfgDb;
import com.elitel.frame.main.entity.CfgExtend;
import com.elitel.frame.main.entity.CfgExtsql;
import com.elitel.frame.main.entity.vo.PageResponseVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component("cacheServiceData")
public class CacheServiceData {
    @Autowired
    private SingleTableServerServiceImpl singleTableServerServiceImpl;
    @Autowired
    private MultipleTableServerServiceImpl multipleTableServerServiceImpl;


    @Cacheable(cacheNames = CacheConfig.DEFAULT, key = "#redisKeystr")
    public List<Map<String, Object>> queryDataAddRedisSingle(
            String redisKeystr,
            CfgDb prop,
            CfgExtend cfgExtend,
            String conQuery,
            String pageNum,
            String pageSize) {
        // PageResponseVo<Map<String, Object>> pageResponse = singleTableServerServiceImpl.queryDataByPage(prop, cfgExtend, pageNum, "500", conQuery);
        // List<Map<String, Object>> viewData = pageResponse.getRows();
        // return viewData;

        return null;
    }

    @Cacheable(cacheNames = CacheConfig.DEFAULT, key = "#redisKeystr")
    public List<Map<String, Object>> queryDataNoPageAddRedis(String redisKeystr, CfgDb prop, CfgExtend cfgExtend, String conQuery) {
        // PageResponseVo pageResponseVo = singleTableServerServiceImpl.querySingleTBList(prop, cfgExtend, conQuery);
        // List rows = pageResponseVo.getRows();
        // return rows;
        return null;
    }

    @Cacheable(cacheNames = CacheConfig.DEFAULT, key = "#redisKeystr")
    public List<Map<String, Object>> queryDataAddRedisMulti(
            String redisKeystr,
            CfgDb cfgDB,
            CfgExtsql cfgExtsql,
            String conQuery,
            String pageNum,
            String pageSize) {
        // PageResponseVo<Map<String, Object>> pageResponse = multipleTableServerServiceImpl.queryDataByPage(cfgDB, pageNum, "500", conQuery, cfgExtsql);
        // List<Map<String, Object>> viewData = pageResponse.getRows();
        // return viewData;
        return null;
    }


    @Cacheable(cacheNames = CacheConfig.DEFAULT, key = "#redisKeystr")
    public PageResponseVo multipleTableAddRedis(String redisKeystr, CfgDb cfgDb, CfgExtsql cfgExtsql, String conQuery){
        PageResponseVo pageResponseVo = multipleTableServerServiceImpl.multipleTableQuery(cfgDb, conQuery, cfgExtsql);
        return pageResponseVo;
    }

    @CachePut(cacheNames = CacheConfig.DEFAULT, key = "#rediskeystr+'_count'")
    public String setRedisCount(String rediskeystr, CfgDb prop, CfgExtend cfgExtend, String conQuery) {
        Long count = singleTableServerServiceImpl.queryDataTotal(prop, cfgExtend, conQuery);
        return String.valueOf(count);
    }

    @Cacheable(cacheNames = CacheConfig.DEFAULT, key = "#rediskeystr+'_count'")
    public Long queryRedisCount(String rediskeystr) {
        return 0L;
    }

}
